package com.yc.http.tomcat.impl;

import com.yc.http.tomcat.HttpServletRequest;
import com.yc.http.tomcat.HttpServletResponse;
import com.yc.http.tomcat.ServletException;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * 定义Servlet
 * 1. 继承
 * 2. 重写 doXXX
 * 3. 配置 注解 + web.xml
 *
 *  jsp = html + java ==> servlet
 */
// @WebServlet("/hello.do")
public class HelloServlet extends HttpServletImpl{

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        PrintWriter writer = response.getWriter();
        response.setContentType("text/html;charset=utf-8");

        String name = request.getParameter("name");
        // 相应对象 会临时保存 append 的内容
        writer.append("<h2>hello "+name+"</h2>");

        // 作业： 获取参数并输出
        // http://127.0.0.1:8080/hello.do?name=zhangsan
        // hello zhangsan

    }
}
